package sim.tests.games.snake;

import sim.Sprite;
import sim.states.BasicGame;

public class SnakeGame extends BasicGame
{
	public static Sprite[][] grid;
	final int GRID_HEIGHT = 20;
	// Makes a tile a square shape
	final int GRID_LENGTH = 12;
	long preTime = 0;
	long aftTime = 300;
	public static SnakeHead  head;

	public static enum CompassDirection
	{
		North, East, South, West
	}

	@Override
	public void init()
	{

		setWorldSize(GRID_HEIGHT, GRID_LENGTH);

		grid = new Sprite[GRID_HEIGHT][GRID_LENGTH];
		head = new SnakeHead(0, 0);
		grid[0][0] = head;
		aftTime = System.currentTimeMillis();
	}

	@Override
	public void update(float delta)
	{
		aftTime = System.currentTimeMillis();
		
		if((aftTime - preTime) > 300)
		{
		preTime = System.currentTimeMillis();

		for (int y = 0; y < GRID_HEIGHT; y++)
		{
			for (int x = 0; x < GRID_LENGTH; x++)
			{
				if (grid[y][x] != null)
					grid[y][x].update(delta);

			}
			
		}
		}
	}

	@Override
	public void draw()
	{
		for (int y = 0; y < GRID_HEIGHT; y++)
		{
			for (int x = 0; x < GRID_LENGTH; x++)
			{
				if (grid[y][x] != null)
					grid[y][x].draw();
			}
		}

	}

}
